/*
 * @(#)SaturnConfigAutoConfiguration.java 1.0 2019年10月29日上午9:44:52
 *
 * Saturn Framework Co.Limt
 * Copyright (c) 2012-2019 tanks, Inc. All rights reserved.
 */
package com.saturn.cloud.config;

import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <dl>
 *    <dt><b>Title:</b></dt>
 *    <dd>
 *    	none
 *    </dd>
 *    <dt><b>Description:</b></dt>
 *    <dd>
 *    	<p>none
 *    </dd>
 * </dl>
 *
 * @author tanks
 * @version 1.0, 2019年10月29日
 * @since saturn-config-spring-boot-starter
 * 
 */
@Configuration
@ConditionalOnProperty(name = "spring.cloud.saturn.config.enabled", matchIfMissing = true)
public class SaturnConfigAutoConfiguration {

	@Bean
	public SatrunConfigProperties nacosConfigProperties(ApplicationContext context) {
		if (context.getParent() != null
				&& BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
						context.getParent(), SatrunConfigProperties.class).length > 0) {
			return BeanFactoryUtils.beanOfTypeIncludingAncestors(context.getParent(),
					SatrunConfigProperties.class);
		}
		SatrunConfigProperties nacosConfigProperties = new SatrunConfigProperties();
		return nacosConfigProperties;
	}
}
